package com.itheima.service.db.Impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.db.UserMapper;
import com.itheimma.service.db.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserServicelmpl implements UserService {

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public Long save(User user) {
        //给用户ID加密
        String securePassword = SecureUtil.md5(user.getPassword());
        user.setPassword(securePassword);
        //保存用户信息
        userMapper.insert(user);    //返回的是影响行数
        return user.getId();
    }

    @Override
    public User findByPhone(String phone) {
        //构建条件查询
        QueryWrapper<User> qw = new QueryWrapper<>();
        //where phone = ?
        qw.eq("phone",phone);
        //使用查询一个用户信息
        return userMapper.selectOne(qw);
    }
}
